package com.ye.zcswzlms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ye.zcswzlms.entity.Users;
import com.ye.zcswzlms.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 叶德辉
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/user")
public class UsersController {
    @Autowired
    UsersServiceImpl usersService;

    @PostMapping("/login")
    String login(@RequestBody Users user){
        QueryWrapper<Users> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("stuNo",user.getStuNo());
        queryWrapper.eq("password",user.getPassword());
       queryWrapper.eq("login",1);
        Users one = usersService.getOne(queryWrapper);
           if (one!=null){

                return "成功";
           }
             return "失败";
    }

    @PostMapping("/register")
    String register(@RequestBody Users user){
       return usersService.register(user);
    }

    @GetMapping("/addAdmin")
    Boolean addAdmin(String stuNo){
        usersService.addAdmin(stuNo);
        return true;
    }
    @GetMapping("/queryByName")
    List<Users> queryByName(String name){
        List<Users> users = usersService.queryByName(name);
        return users;
    }
}
